﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        var wireTransfer, remittanceAccount, cryptoCurrency
        var fromCurrency, withdrawCurrency
        var channelId
        var mothod = 1
        var price
        var renderTable;
        var userType = 0;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            treetable: 'treetable-lay/treetable',
            index: 'lib/index'
        }).use(['table', 'form', 'treetable', 'index', 'upload'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , upload = layui.upload
                , table = layui.table
                , element = layui.element
                , treetable = layui.treetable;
            top.SetListPageLanguage(layui);

            //出金提交
            form.on('submit(submit)', function (data) {
                //var channelId = $("#wireTransferCurrency option:selected").val()
                //var mothod = mothod
                var amount = $("#amount").val().trim().replace(/,/g, '');
                var password = $("#password").val()
                var remarks = $("#remark").val()
                if (amount === "") {
                    top.ShowMessageByKey(layui, top.lang.withdrawAmountError, 0, 1000);
                    return false;
                }
                layui.layer.confirm(top.lang.confirmWithdrwa + "$" + amount, {
                    title: top.lang.confirmTitle,
                    btn: [top.lang.confirmBtn, top.lang.closeBtn]
                }, function (index, layero) {
                    $.ajax({
                        type: "POST",
                        url: "/Assets/InternalTransfer",
                        data: {
                            "amount": amount,
                            "password": password,
                            "remarks": remarks,
                        },
                        async: true,
                        error: function (request) {
                            alert("Connection error");
                        },
                        beforeSend: function (xhr) {
                            layui.layer.load();
                        },
                        success: function (data) {
                            var item = eval(data);
                            if (item.code == 0) {
                                top.ShowMessageByKey(layui, item.msg, 6, 1000, function () {
                                    location.reload();
                                });
                            } else {
                                top.ShowMessageByKey(layui, item.msg, 0, 1000);
                            }
                            layer.closeAll('loading');
                        }
                    });
                });
                return false;
            });
        
            $("#gotoSePersonal").click(function () {
                parent.layui.index.openTabsPage("/Personal/Index");
                //初始化导航选项卡（选中新建标签卡）
                parent.layui.element.render('nav');
            });

            $("#gotoSetFinancial").click(function () {
                parent.layui.index.openTabsPage("/Personal/Index");
                //初始化导航选项卡（选中新建标签卡）
                parent.layui.element.render('nav');
            });

            $("#gotoSetTradePassword").click(function () {
                parent.layui.index.openTabsPage("/Personal/TradePassword");
                //初始化导航选项卡（选中新建标签卡）
                parent.layui.element.render('nav');
            });

                 //复制
            $('.refresh').click(function () {
                $.ajax({
                    type: "POST",
                    url: "/Assets/GetBalance",
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            $('#crmBalance').text(item.data.crmBalance)
                            $('#mt5Balance').text(item.data.mt5Balance)
                            top.ShowMessageByKey(layui, item.msg, 6, 1000)
                        } else {
                            top.ShowMessageByKey(layui, item.msg, 0, 1000);
                        }
                        layer.closeAll('loading');
                    }
                });
            })

            //光标离开输入的金额四舍五入并保留4位小数
            $("#amount").blur(function () {
                var obj = this.value;
                var mnyReg = /^([1-9][0-9]*|(([0]\.[0-9]{0,2}[1-9]\d*|[1-9][0-9]*\.\d*)))$/;//根据需求修改
                if (!(mnyReg.test(obj))) {
                    top.AlertByKey(layui, "enterNotIsNumber", 0);
                    return;
                }
                var n = 2; //保留得小数位
                obj = parseFloat(obj).toFixed(n);
                var left = obj.split(".")[0].split("").reverse();
                var right = obj.split(".")[1];
                var total = new Array();
                for (i = 0; i < left.length; i++) {
                    total.push(left[i]);
                    if ((i + 1) % 3 == 0 && (i + 1) != left.length) {
                        total.push(",");
                    }
                }
                $("#amount").val(total.reverse().join("") + "." + right);
            });

            //光标进入，去除金额千分位，并去除小数后面多余的0
            $("#amount").focus(function () {
                var oldMny = this.value.replace(/,/g, '');
                if (oldMny.indexOf(".") > 0) {
                    oldMny = oldMny.replace(/0+?$/, "");//去除尾部多余的0
                    oldMny = oldMny.replace(/[.]$/, "");//如果最后一位是.则去掉
                }
                this.value = oldMny;
            });
        });


    </script>
}
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
        @if (!ViewBag.hasMt5User)
        {
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body" style="text-align:center;">
                        <blockquote class="layui-elem-quote" id="setPersonal" lay-event="setPersonal">请先完善您的个人信息</blockquote>
                        <button type="button" class="layui-btn" id="gotoSetPersonal" lay-event="gotoSePersonal">立即前往</button>
                    </div>
                </div>
            </div>
        }
        else
        {
            @if (!ViewBag.hasWallet)
            {
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body" style="text-align:center;">
                            <blockquote class="layui-elem-quote" id="setFinancial" lay-event="setFinancial">请先完善您的财务认证</blockquote>
                            <button type="button" class="layui-btn" id="gotoSetFinancial" lay-event="gotoSetFinancial">立即前往</button>
                        </div>
                    </div>
                </div>
            }
            else
            {
                @if (!ViewBag.hasTradePassword)
                {
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-body" style="text-align:center;">
                                <blockquote class="layui-elem-quote" id="setTradePassword" lay-event="setTradePassword">请先设置您的资金密码</blockquote>
                                <button type="button" class="layui-btn" id="gotoSetTradePassword" lay-event="gotoSetTradePassword">立即前往</button>
                            </div>
                        </div>
                    </div>
                }
                else
                {
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-body">
                                <form class="layui-form" id="withdrawForm">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label" lay-event="myWallet" style="width:100px;">佣金钱包（付）</label>
                                        <div class="layui-input-block"  style="margin-left:130px;">
                                            <label class="form-label  mt5user" id="crmBalance" name="crmBalance">@ViewBag.crmWalletBalance</label>
                                            <label class="form-label mt5user" style="display:inline-block">USD</label>
                                            <i class="layui-icon layui-icon-refresh-3 refresh"></i>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label" lay-event="tradeWallet" style="width:100px;">交易钱包（收）</label>
                                        <div class="layui-input-block" style="margin-left:130px;">
                                            <label class="layui-form-label  mt5user" id="mt5user" name="mt5user" lay-event="mt5user">@ViewBag.login</label>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label" lay-event="mt5Balance" style="width:100px;">可用金额</label>
                                        <div class="layui-input-block" style="margin-left:130px;">
                                            <label class="form-label mt5user" id="mt5Balance" name="mt5Balance">@ViewBag.mt5Balance</label>
                                            <label class="form-label mt5user" style="display:inline-block">USD</label>
                                            <i class="layui-icon layui-icon-refresh-3 refresh"></i>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-group">
                                            <div class="layui-input-prefix" lay-event="transferamounttitle" style="width:130px!important">转账金额</div>
                                            <input type="text" placeholder="" class="layui-input" id="amount" name="amount">
                                            <div class="layui-input-split layui-input-suffix">
                                                USD
                                            </div>
                                            <label style="display:inline-block;display:none; padding:0 10px;color:red;" id="availableAmount" name="availableAmount" lay-event="availableAmount">出金金额不能大于可用金额</label>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-group">
                                            <div class="layui-input-prefix" style="width:130px!important" id="feesTitle" lay-event="feesTitle">手续费</div>
                                            <label class="form-label" style="padding-left:0px; text-align:left;" name="transferFeestip" id="transferFeestip" lay-event="transferFeestip">转出手续费将以实际为准，从转出金额中扣除</label>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label" style="width:100px;" id="tradePwd" lay-event="tradePwd">资金密码</label>
                                        <div class="layui-input-block" style="margin-left:130px;">
                                            <input type="password" autocomplete="off" placeholder="tradePwd" class="layui-input" id="password">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label" style="width:100px;" lay-event="remark">备注</label>
                                        <div class="layui-input-block" style="margin-left:130px;">
                                            <input type="text" autocomplete="off" placeholder="remark" class="layui-input" id="remark">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block" style="margin-left:130px;">
                                            <button type="submit" class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                }
            }
        }        
    </div>
</div>